package
{
	import component.headerNavigation.data.MenuData;
	import component.headerNavigation.data.MenuItemData;
	import component.headerNavigation.event.PathEvent;
	import component.headerNavigation.homeMenu.HomeMenu;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.FocusEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	import obecto.core.FLApplication;
	import obecto.event.FLEvent;

	[SWF(backgroundColor="0xCDCDCD")]
	public class HomeMenuSample extends FLApplication
	{
		private var homeMenu : HomeMenu;
		private var currentPathTextField : TextField;
		
		public function HomeMenuSample()
		{
			super();
			
			stage.frameRate = 35;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			homeMenu = new HomeMenu();
			homeMenu.addEventListener(FLEvent.CREATION_COMPLETE, handleHomeMenuCreationComplete);
			homeMenu.addEventListener(PathEvent.PATH_CHANGE, handleHomeMenuPathChange);
			homeMenu.itemsData = 
				[
				new MenuData("1", { label: "1", enabled: true },
					[
					new MenuItemData("1.1", { label: "1", enabled: true }),
					new MenuItemData("1.2", { label: "2", enabled: true }),
					new MenuItemData("1.3", { label: "3", enabled: true })
					]),
				new MenuData("2", { label: "2", enabled: true },
					[
					new MenuItemData("2.1", { label: "1", enabled: true }),
					new MenuItemData("2.2", { label: "2", enabled: true }),
					new MenuItemData("2.3", { label: "3", enabled: true })
					]),
				new MenuData("3", { label: "3", enabled: true },
					[
					new MenuItemData("3.1", { label: "1", enabled: true }),
					new MenuItemData("3.2", { label: "2", enabled: true }),
					new MenuItemData("3.3", { label: "3", enabled: true })
					])
				];
			
			currentPathTextField = new TextField();
			currentPathTextField.addEventListener(FocusEvent.FOCUS_OUT, handleCurrentPathTextFieldFocusOut);
			currentPathTextField.type = TextFieldType.INPUT;
			currentPathTextField.autoSize = TextFieldAutoSize.LEFT;
			currentPathTextField.background = true;
			currentPathTextField.backgroundColor = 0xFFFFFF;
			currentPathTextField.defaultTextFormat = new TextFormat(null, 28);
			currentPathTextField.text = homeMenu.selectedPath;
			
			addChild(currentPathTextField);
		}
		
		private function handleHomeMenuCreationComplete(e : FLEvent) : void 
		{
			homeMenu.x = 100;
			homeMenu.y = 110;
			
			addChild(homeMenu);
		}
		
		private function handleHomeMenuPathChange(e : PathEvent) : void
		{
			currentPathTextField.text = homeMenu.selectedPath;
		}
		
		private function handleCurrentPathTextFieldFocusOut(e : FocusEvent) : void
		{
			homeMenu.selectedPath = currentPathTextField.text;
		}
		
	}
}